package com.xihua.sx.controller;

import com.xihua.sx.pojo.EditPassword;
import com.xihua.sx.pojo.User;
import com.xihua.sx.service.UserService;
import com.xihua.sx.utils.ResponseMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
//@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping( value = "/login",method = RequestMethod.POST)
    public ResponseMessage login(@RequestBody User user){
        return userService.login(user.getUsername(),user.getPassword());
    }

    @RequestMapping(value = "editPassword",method = RequestMethod.POST)
    public ResponseMessage editPassword(@RequestBody EditPassword editPassword){
        return userService.editPassword(editPassword);
    }

    @RequestMapping(value = "/registerUser")
    public ResponseMessage registerUser(@RequestBody User user){
        return userService.registerUser(user.getUsername(),user.getPassword());
    }
}
